#include "createnewalbum.h"

CreateNewAlbum::CreateNewAlbum(QWidget *parent)
    : QWidget{parent}
{
    setWindowFlags(Qt::Tool|Qt::FramelessWindowHint|Qt::Window);
    setAttribute(Qt::WA_TranslucentBackground);
    setFixedSize(600,500);

    albumnamelabel=new QLabel("歌单名：",this);
    taglabel=new QLabel("标签：",this);
    introlabel=new QLabel("介绍：",this);
    albumnameline=new QLineEdit(this);
    tagline=new QLineEdit(this);
    introline=new QLineEdit(this);
    okbtn=new QPushButton("确定",this);
    canclebtn=new QPushButton("取消",this);
    mainlayout=new QVBoxLayout(this);

    QHBoxLayout*hlayout=new QHBoxLayout;
    hlayout->addWidget(albumnamelabel);
    hlayout->addWidget(albumnameline);
    mainlayout->addLayout(hlayout);

    hlayout=new QHBoxLayout;
    hlayout->addWidget(taglabel);
    hlayout->addWidget(tagline);
    mainlayout->addLayout(hlayout);

    hlayout=new QHBoxLayout;
    hlayout->addWidget(introlabel);
    hlayout->addWidget(introline);
    mainlayout->addLayout(hlayout);

    hlayout=new QHBoxLayout;
    hlayout->addWidget(okbtn);
    hlayout->addWidget(canclebtn);
    mainlayout->addLayout(hlayout);

    SetLineStyleSheet(albumnameline);
    SetLineStyleSheet(tagline);
    SetLineStyleSheet(introline);

    QFont f1("Microsoft YaHei",12),f2("Microsoft YaHei",14);
    albumnamelabel->setFont(f2);
    taglabel->setFont(f2);
    introlabel->setFont(f2);
    albumnameline->setFont(f1);
    tagline->setFont(f1);
    introline->setFont(f1);



    connect(okbtn,&QPushButton::clicked,this,[this]{
        albumname=albumnameline->text();
        tag=tagline->text();
        intro=introline->text();
        albumnameline->clear();
        tagline->clear();
        introline->clear();
        hide();
        if(!albumname.isEmpty()&&!tag.isEmpty()&&!intro.isEmpty())
        emit ok();
    });
    connect(canclebtn,&QPushButton::clicked,this,[this]{
        albumnameline->clear();
        tagline->clear();
        introline->clear();
        hide();
        emit cancle();
    });
}

void CreateNewAlbum::paintEvent(QPaintEvent*e)
{
    Q_UNUSED(e)
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setBrush(QColor("white")); // 背景颜色
    painter.setPen(Qt::NoPen); // 无边框
    painter.drawRoundedRect(this->rect(), 10, 10);
}

void CreateNewAlbum::SetLineStyleSheet(QLineEdit*line)
{
    line->setStyleSheet("QLineEdit {"
                    //"   color: #ffffff;"
                    //"   background-color: #ea3e3e;"  // 背景颜色
                    "   padding: 5px;"
                    "   border-radius: 10px;"         // 圆角
                    "   border: 1px solid #f28b8b;"   // 边框颜色
                    "}"
                    );
}
